package com.gxa.logistics.controller;

import com.gxa.logistics.common.base.PageWrapperDTO;
import com.gxa.logistics.common.base.RespResult;
import com.gxa.logistics.domain.dto.EmployeeReqListDTO;
import com.gxa.logistics.domain.dto.EmployeeSaveDTO;
import com.gxa.logistics.domain.dto.EmployeeUpdateDTO;
import com.gxa.logistics.domain.vo.EmployeeVO;
import com.gxa.logistics.service.EmployeeService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "用户管理-员工管理")
@RestController
@RequestMapping("/employee")
@Slf4j
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    /**
     * 获取用户列表
     */
    @ApiOperation(value = "获取员工列表-分页", notes = "获取员工列表-分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo",value = "当前页码数",defaultValue = "1",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "pageSize",value = "每页显示条数",defaultValue = "10",paramType = "query",dataType = "String")
    })
    @PostMapping("/list")
    public RespResult<PageWrapperDTO<EmployeeVO>> list(@RequestBody EmployeeReqListDTO employeeReqListDTO){
        System.out.println(employeeReqListDTO.getEmployeeName());
        return employeeService.list(employeeReqListDTO);
    }

    @ApiOperation(value = "根据id查询员工", notes = "根据id查询员工")
    @GetMapping("/find")
    public RespResult<List<EmployeeVO>> find(Integer employeeId){
        return employeeService.findById(employeeId);
    }

    /**
     * 新增员工
     */
    @ApiOperation(value = "新增保存", notes = "新增保存")
    @PostMapping("/save")
    public RespResult save(@RequestBody @ApiParam(name = "data",value = "系统用户添加实体") @Validated EmployeeSaveDTO employeeSaveDTO) {
        // 保存

        employeeService.insertEmployee(employeeSaveDTO);
        return RespResult.success();
    }

    /**
     * 修改用户
     */
    @ApiOperation(value = "修改保存", notes = "修改保存")
    @PostMapping("/update")
    public RespResult update(@RequestBody @ApiParam(name = "data",value = "系统用户修改实体") EmployeeUpdateDTO employeeUpdateDTO) {
        employeeService.updateEmployee(employeeUpdateDTO);
        return RespResult.success();
    }


    /**
     * 删除用户
     */
    @ApiOperation(value = "删除用户", notes = "删除用户")
    @ApiImplicitParam(name = "employee_id",value = "员工id",required = true,dataType = "String",paramType = "path")
    @PostMapping("/delete/{employee_id}")
    public RespResult delete(@PathVariable("employee_id") Integer employeeId){
        employeeService.deleteEmployeeById(employeeId);
        return RespResult.success();
    }

    /**
     * 冻结用户
     */
    @ApiOperation(value = "冻结用户", notes = "冻结用户")
    @ApiImplicitParam(name = "employee_id",value = "员工id",required = true,dataType = "String",paramType = "path")
    @PostMapping("/freeze/{employee_id}")
    public RespResult freeze(@PathVariable("employee_id") Integer employeeId){
        employeeService.freezeEmployeeById(employeeId);
        return RespResult.success();
    }


}
